home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Utilities / Scion / ARexx / Unrelated.rexx < prev    next >
OS/2 REXX Batch file  |  1997-11-04  |  7KB  |  255 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  * $VER: Unrelated 1.03 (12 Oct 1997)
  4.  *                                                                          *
  5.  *                      Written by Robbie Akins                             *
  6.  *                                                                          *
  7.  * Adapted from ARexx scripts by Freddy Ariës - Many thanks Freddy :-)      *
  8.  *                                                                          *
  9.  * ARexx script to find "unrelated" people in the database.                 *
  10.  * That is, it will locate all those people who have no parents and who     *
  11.  * have no marriages recorded (and hence cannot have any recorded children) *
  12.  *                                                                          *
  13.  * This script uses (by default) the rexxreqtools.library (which requires   *
  14.  * a version of reqtools larger than 2.0 and rexxsyslib.library)            *
  15.  * If you do not have these, run SetDefaults.rexx to change the settings.   *
  16.  *                                                                          *
  17.  * 1.02: Now uses preference file for default settings (by Freddy Ariës)    *
  18.  * 1.03: Now supports v5 commands GETFIRSTIRN/GETNEXTIRN/GETLASTIRN         *
  19.  *                                                                          *
  20.  ****************************************************************************/
  21.  
  22. options results
  23. arg outname outval
  24.  
  25. versionstr = "1.03"
  26.  
  27. /* Don't change the settings here! Run SetDefaults.rexx instead! */
  28. usereq = 1; pscr = "SCIONGEN"
  29. outp = 1; output = stdout; scrdev = stdout
  30.  
  31. scrname = "CON:0//639//Scion Output/AUTO/SCREEN"
  32. NL = '0A'x
  33.  
  34. signal on IOERR
  35.  
  36. /* parse command line options, to enable calling the script automatically,
  37.  * eg. from a function key
  38.  */
  39.  
  40. do while outname = '?'
  41.   writeln(stdout, "OUTFILE/A,QUIET/S,NOREQ/S ")
  42.   pull outname outval
  43. end
  44.  
  45. /* read preferences file */
  46.  
  47. if open(pfile, 'ENV:Scion/ScionRexx.prefs', 'r') then do
  48.   do while ~eof(pfile)
  49.     inln = readln(pfile)
  50.     if inln ~= "" then do
  51.       wstr = upper(word(inln, 1))
  52.       if wstr = "USEREQ" then
  53.         usereq = 1
  54.       else if wstr = "NOUSEREQ" then
  55.         usereq = 0
  56.       else if wstr = "PUBSCREEN" then
  57.         pscr = strip(delstr(inln, 1, length(wstr)), 'b', ' "')
  58.     end
  59.   end
  60.   close(pfile)
  61. end
  62.  
  63. if pscr = "" | (pscr ~= "WORKBENCH" & ~show('p', pscr)) then
  64.   pscr = "SCIONGEN"
  65. scrname = scrname||pscr
  66.  
  67. /* command line options get priority over global settings */
  68.  
  69. if outname ~= "" then do
  70.   if outname = "QUIET" | outname = "NOREQ" then do
  71.     outval = outname; outname = ""
  72.   end
  73. end
  74.  
  75. if outval = "QUIET" then do
  76.   outp = 0; usereq = 0
  77. end
  78. else if outval = "NOREQ" then usereq = 0
  79.  
  80. if ~show('l','rexxarplib.library') then do
  81.   if exists('libs:rexxarplib.library') then
  82.     call addlib('rexxarplib.library',0,-30,0)
  83. end
  84.  
  85. screentofront(pscr)
  86.  
  87. if usereq & ~show('l','rexxreqtools.library') then do
  88.   if exists('libs:rexxreqtools.library') then
  89.     call addlib('rexxreqtools.library',0,-30,0)
  90.   else do
  91.     usereq = 0; outp = 1
  92.     Tell("Unable to open rexxreqtools.library - using text output")
  93.   end
  94. end
  95.  
  96. /* These first few lines were stolen from Peter Billings - thanks Peter ;-) */
  97. if ~show('P','SCIONGEN') then do
  98.   EndString('I am sorry to say that the SCION Genealogist' || NL ||,
  99.     'database is not available. Please start the' || NL ||,
  100.     'SCION program BEFORE using this script!')
  101. end
  102.  
  103. myport = "SCIONGEN"
  104. address value myport
  105. GETDBNAME
  106. dbname = upper(RESULT)
  107.  
  108. CurrIRN = 1
  109.  
  110. if outp & ~usereq then do
  111.   if pscr ~= "WORKBENCH" then do
  112.     scrdev = 'SCNLNKSCR'
  113.     if ~open(scrdev, scrname, 'w') then scrdev = stdout
  114.   end
  115.   Tell("Scion Unrelated Person Finder v"||versionstr||" by Robbie Akins")
  116.   Tell("Current Scion database: "||dbname)
  117. end
  118.  
  119. if (prgvers >= 5) then
  120. do
  121.   GETFIRSTIRN
  122.   CurrIRN = RESULT
  123.   GETLASTIRN
  124.   TotalIRN = RESULT
  125. end
  126. else do
  127.   GETTOTALIRN
  128.   TotalIRN = RESULT
  129.   CurrIRN = 1
  130. end
  131.  
  132. if TotalIRN = 0 then
  133.   EndString("No database loaded - exiting...")    /* No database to work on! */
  134.  
  135. /* It's a good habit to add an ".UNREL" extension to "unrelated" files */
  136. dblen = length(dbname)
  137. if dblen>6 & right(dbname, 6)=".Scion" then dbname=left(dbname, dblen - 6)
  138.  
  139. if outname = "" then do
  140.   if outp then do
  141.     if usereq then do
  142.        odev = rtezrequest('Current Scion database: '||dbname||,
  143.        NL||'Where should the output be sent to?'||,
  144.        NL,' _File |_Printer|_Screen|_Nowhere','Unrelated People v'||versionstr||' by Robbie Akins','rt_pubscrname = '||PSCR)
  145.  
  146.       select
  147.         when odev = 1 then do
  148.           /* We need a file requester for further data */
  149.           outname = rtfilerequest(,dbname||'.UNREL','Output filename',,'rtfi_buffer = true   rt_pubscrname = '||PSCR||'   rtfi_initialpath = RAM:',)
  150.           if outname = '' then
  151.             outname = dbname||'.UNREL'
  152.         end
  153.         when odev = 2 then
  154.           outname = 'PRT:'
  155.         when odev = 3 then
  156.           outname = 'STDOUT'
  157.         otherwise
  158.           EXIT
  159.           /* You selected 'Nowhere' */
  160.       end
  161.     end
  162.     else do
  163.       Tell("Enter output file (filename with complete path, or PRT: for printer,")
  164.       TellNN("or STDOUT for screen): ")
  165.       outname = readln(scrdev)
  166.       outname = strip(outname, 'b', ' "')
  167.       Tell("Destination: "||outname)
  168.       TellNN("Continue (y/n)? ")
  169.       conf = readln(scrdev)
  170.       conf = upper(left(conf, 1))
  171.       /* Note that left works on empty strings ("") too! */
  172.       if conf ~= "Y" then
  173.         EndString("Goodbye...")
  174.       Tell("")
  175.     end
  176.   end
  177.   else
  178.     outname = "RAM:"dbname".UNREL"
  179.     /* If we're not allowed to use stdout, default to this filename */
  180. end
  181.  
  182. if outname ~= "STDOUT" then do
  183.   output = 'OUTPUT'
  184.   if ~open(output, outname, "w") then
  185.     EndString("ERROR: Unable to open output file.")
  186. end
  187. else
  188.   output = scrdev
  189.  
  190. writeln(output, "List of unrelated people:")
  191. do while (CurrIRN > 0) & (CurrIRN <= TotalIRN)
  192.     EXISTPERSON CurrIRN
  193.         if RESULT = 'YES' then do
  194.         GETNUMMARRY CurrIRN
  195.         if RESULT = 0 then do
  196.             /* No marriages. Possible candidate */
  197.             GETPARENTS CurrIRN
  198.             if RESULT = '' then do
  199.             /* This person is unrelated */
  200.             GETLASTNAME CurrIRN
  201.             last = result
  202.             GETFIRSTNAME CurrIRN
  203.             first = result
  204.             str = "IRN" CurrIRN": "Last", "First
  205.             writeln(output, str)
  206.         end
  207.         end
  208.     end
  209.  
  210.   /* Do next possible person */
  211.   if (prgvers >= 5) then
  212.   do
  213.      GETNEXTIRN CurrIRN
  214.      CurrIRN = RESULT
  215.   end
  216.   else do
  217.      CurrIRN = CurrIRN + 1
  218.   end
  219. end
  220.  
  221. EndString("Done.")
  222. EXIT
  223.  
  224. Tell: PROCEDURE EXPOSE outp scrdev
  225. parse arg str
  226. if outp then writeln(scrdev, str)
  227. return 0
  228.  
  229. TellNN: PROCEDURE EXPOSE outp scrdev
  230. parse arg str
  231. if outp then writech(scrdev, str)
  232. return 0
  233.  
  234. EndString: PROCEDURE EXPOSE outp output usereq scrdev pscr
  235. parse arg str
  236. /* If you turned off stdout, no error messages will be shown! */
  237. if usereq then
  238.   rtezrequest(str,'E_xit','Finder Message:','rt_pubscrname = '||pscr)
  239. else do
  240.   Tell(str || '0A'x)
  241. end
  242. if outp & ~usereq & (scrdev ~= stdout) then do
  243.   Tell("Press <return> to exit.")
  244.   readln(scrdev)
  245.   close(scrdev)
  246. end
  247. close(output)
  248. EXIT
  249.  
  250. IOERR:
  251.   bline = SIGL
  252.   say "I/O error #"||RC||" detected in line "||bline||":"
  253.   say sourceline(bline)
  254.   EXIT
  255.